var t = getApp();

Page({
    data: {
        page: 1,
        shareBox: !1
    },
    onLoad: function(t) {
        this.getData();
    },
    del: function(t) {
        var o = t.currentTarget.dataset.id;
        console.log(o), this.dels(o);
    },
    edit: function(t) {
        var o = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageE/groupCode/groupCodeEdit/groupCodeEdit?id=" + o
        });
    },
    codeData: function(t) {
        var o = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageE/groupCode/groupCodeData/groupCodeData?id=" + o
        });
    },
    saveImg: function() {
        wx.getSetting({
            success: function(t) {
                t.authSetting["scope.writePhotosAlbum"] || wx.authorize({
                    scope: "scope.writePhotosAlbum",
                    success: function() {
                        console.log("授权成功");
                    }
                });
            }
        });
        var t = this.data.minImga;
        wx.downloadFile({
            url: t,
            success: function(t) {
                console.log(t), wx.saveImageToPhotosAlbum({
                    filePath: t.tempFilePath,
                    success: function(t) {
                        wx.showToast({
                            title: "保存成功",
                            icon: "none",
                            duration: 2e3
                        });
                    },
                    fail: function(t) {
                        console.log(t), "saveImageToPhotosAlbum:fail auth deny" === t.errMsg && (console.log("当初用户拒绝，再次发起授权"), 
                        wx.openSetting({
                            success: function(t) {
                                t.authSetting["scope.writePhotosAlbum"] ? wx.showToast({
                                    icon: "none",
                                    title: "获取权限成功,再次长按保存图片",
                                    duration: 1500
                                }) : wx.showToast({
                                    icon: "none",
                                    title: "获取权限失败,保存图片需要用户授权",
                                    duration: 1500
                                });
                            }
                        }));
                    },
                    complete: function(t) {
                        console.log(t);
                    }
                });
            }
        });
    },
    CloseBtn: function() {
        this.setData({
            shareBox: !1
        });
    },
    shareBox: function(o) {
        var e = o.currentTarget.dataset.id;
        wx.showLoading({
            title: "加载中"
        });
        var a = this, s = t.getNetAddresss("plugin.group-code.api.group-code.get-share-poster");
        t._postNetWork({
            url: s,
            data: {
                id: e,
                ingress: "weChatApplet"
            },
            success: function(t) {
                var o = t.data;
                wx.hideLoading({
                    success: function(t) {}
                }), 1 == o.result ? (console.log(o), a.setData({
                    minImga: o.data.image_url,
                    base: o.data.base64Image,
                    shareBox: !0
                })) : (wx.showToast({
                    title: o.msg,
                    icon: "none"
                }), console.log(o.msg));
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        if (this.data.current_page >= this.data.last_page) wx.showToast({
            title: "没有更多了",
            icon: "none",
            duration: 1e3
        }); else {
            var t = this.data.page + 1;
            this.setData({
                page: t
            }), this.getMoreData();
        }
    },
    onShareAppMessage: function(t) {
        var o = t.target.dataset.id;
        if (console.log(o), o) return console.log(this.data.list[o].code_name), {
            title: this.data.list[o].code_name,
            path: "/packageE/groupCode/groupCodeLabel/groupCodeLabel?id=" + this.data.list[o].id
        };
    },
    dels: function(o) {
        var e = this, a = t.getNetAddresss("plugin.group-code.api.group-code.deleted-group-code");
        t._postNetWork({
            url: a,
            data: {
                id: o
            },
            success: function(t) {
                var o = t.data;
                1 == o.result ? (console.log(o), wx.showToast({
                    title: o.msg,
                    icon: "none",
                    success: function() {
                        e.getData();
                    }
                })) : (wx.showToast({
                    title: o.msg,
                    icon: "none"
                }), console.log(o.msg));
            }
        });
    },
    getData: function() {
        var o = this, e = t.getNetAddresss("plugin.group-code.api.group-code.my-group-code");
        t._postNetWork({
            url: e,
            data: {
                page: this.data.page
            },
            success: function(t) {
                var e = t.data;
                1 == e.result ? (console.log(e), o.setData({
                    list: e.data.list.data,
                    current_page: e.data.list.current_page,
                    last_page: e.data.list.last_page
                })) : (wx.showToast({
                    title: e.msg,
                    icon: "none"
                }), console.log(e.msg));
            }
        });
    },
    getMoreData: function() {
        var o = this, e = t.getNetAddresss("plugin.group-code.api.group-code.my-group-code");
        t._postNetWork({
            url: e,
            data: {
                page: this.data.page
            },
            success: function(t) {
                var e = t.data;
                1 == e.result ? (console.log(e), o.setData({
                    list: e.data.list.data,
                    current_page: e.data.list.current_page,
                    last_page: e.data.list.last_page
                })) : (wx.showToast({
                    title: e.msg,
                    icon: "none"
                }), console.log(e.msg));
            }
        });
    }
});